<?php

namespace App\Http\Middleware;

use Closure;
use App\Facades\AuthService;

/**
 * AuthMember.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class MemberAuth
{

    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure                 $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(! AuthService::check()){
            return redirect('/login');
        }

        $user = AuthService::user();

        $request = $request->setUserResolver(function() use($user){
            return $user;
        });

        app('cmp')->config->set('token',$user->token->access_token);

        return $next($request);
    }
}
